//
//  BaziLifeInfoViewController.m
//  心水宝典
//
//  Created by zr on 2018/9/3.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "BaziLifeInfoViewController.h"


@interface BaziLifeInfoViewController ()

@property (nonatomic, weak)UIScrollView * scrollView;
@property (nonatomic, strong)UIImageView * backImageView;
@property (nonatomic, strong)UIImageView * topImageView;
@property (nonatomic, strong)UIImageView * oneImageView;
@property (nonatomic, strong)UIImageView * twoImageView;
@property (nonatomic, strong)UIImageView * threeImageView;
@property (nonatomic, strong)UIImageView * fourImageView;
@property (nonatomic, strong)UIImageView * fiveImageView;
@property (nonatomic, strong)UIImageView * sixImageView;
@property (nonatomic, strong)UILabel * topLabel;
@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, strong)UILabel * fourLabel;
@property (nonatomic, strong)UILabel * fiveLabel;
@property (nonatomic, strong)UILabel * sixLabel;
@property (nonatomic, strong)UILabel * oneSubLabel;
@property (nonatomic, strong)UILabel * twoSubLabel;
@property (nonatomic, strong)UILabel * threeSubLabel;
@property (nonatomic, strong)UILabel * fourSubLabel;
@property (nonatomic, strong)UILabel * fiveSubLabel;
@property (nonatomic, strong)UILabel * sixSubLabel;


@end

@implementation BaziLifeInfoViewController


- (void)viewWillAppear:(BOOL)animated{
    
    [[SuanNetWorkTool sharedTools] POST:@"/index/Liuhedivine/horoscope" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary * data = responseObject[@"data"];
        
        self.oneSubLabel.text = data[@"character"];
        self.twoSubLabel.text = data[@"education"];
        self.threeSubLabel.text = data[@"kinsman"];
        self.fourSubLabel.text = data[@"health"];
        self.fiveSubLabel.text = data[@"marriage"];
        self.sixSubLabel.text = data[@"cause"];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = WHITE_COLOR;
    
    [self setupNav];
    [self setupUI];
}


- (void)setupNav{
    
    self.title = @"算命结果";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    //    backButton.frame = CGRectMake(0, 0, 20 * SCREENH6, 20 * SCREENH6);
    backButton.size = CGSizeMake(20 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}


- (void)setupUI{
    
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    
    scrollView.bounces = NO;
    //    scrollView.scrollEnabled = YES;
    scrollView.alwaysBounceVertical = YES;
    scrollView.alwaysBounceHorizontal = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREENH_HEIGHT + 750 * SCREENH6);
    //    scrollView.userInteractionEnabled = YES;
    
    self.scrollView = scrollView;
    
    [self.view addSubview:self.scrollView];

    
    self.backImageView = [[UIImageView alloc] initWithFrame:self.scrollView.bounds];
    self.backImageView.size = self.scrollView.contentSize;
    self.backImageView.image = ImageNamed(@"bjbb");

    [self.scrollView addSubview:self.backImageView];
    
    self.topImageView = [self setupImageViewWithImage:@"biaoti"];
    [self.scrollView addSubview:self.topImageView];
    self.oneImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.oneImageView];
    self.twoImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.twoImageView];
    self.threeImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.threeImageView];
    self.fourImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.fourImageView];
    self.fiveImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.fiveImageView];
    self.sixImageView = [self setupImageViewWithImage:@"duobianxing"];
    [self.scrollView addSubview:self.sixImageView];
    
    self.topLabel = [self setupLabelWithString:@"一帆风顺" WithType:@"title"];
    [self.topImageView addSubview:self.topLabel];
    self.oneLabel = [self setupLabelWithString:@"性格" WithType:@"title"];
    [self.scrollView addSubview:self.oneLabel];
    self.twoLabel = [self setupLabelWithString:@"婚姻" WithType:@"title"];
    [self.scrollView addSubview:self.twoLabel];
    self.threeLabel = [self setupLabelWithString:@"亲属" WithType:@"title"];
    [self.scrollView addSubview:self.threeLabel];
    self.fourLabel = [self setupLabelWithString:@"健康" WithType:@"title"];
    [self.scrollView addSubview:self.fourLabel];
    self.fiveLabel = [self setupLabelWithString:@"学历" WithType:@"title"];
    [self.scrollView addSubview:self.fiveLabel];
    self.sixLabel = [self setupLabelWithString:@"事业" WithType:@"title"];
    [self.scrollView addSubview:self.sixLabel];
    
    self.oneSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.oneSubLabel];
    self.twoSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.twoSubLabel];
    self.threeSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.threeSubLabel];
    self.fourSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.fourSubLabel];
    self.fiveSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.fiveSubLabel];
    self.sixSubLabel = [self setupLabelWithString:@"" WithType:@"sub"];
    [self.scrollView addSubview:self.sixSubLabel];
}


- (void)viewDidLayoutSubviews{
    
//    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.trailing.top.bottom.mas_equalTo(self.scrollView);
//    }];
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.scrollView);
        make.top.mas_equalTo(self.scrollView).offset(20 * SCREENH6);
        make.width.mas_equalTo(228 * SCREENH6);
        make.height.mas_equalTo(60 * SCREENH6);
    }];
    
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.topImageView);
        make.centerY.mas_equalTo(self.topImageView);
    }];
    
    [self.oneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.topImageView.mas_bottom).offset(15 * SCREENH6);
        make.width.height.mas_equalTo(12 * SCREENH6);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.oneImageView);
        make.leading.mas_equalTo(self.oneImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.oneSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneImageView);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.oneImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.twoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.width.height.mas_equalTo(self.oneImageView);
        make.top.mas_equalTo(self.oneSubLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.twoImageView);
        make.leading.mas_equalTo(self.twoImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.twoSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.oneSubLabel);
        make.top.mas_equalTo(self.twoImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.threeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.width.height.mas_equalTo(self.twoImageView);
        make.top.mas_equalTo(self.twoSubLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.threeImageView);
        make.leading.mas_equalTo(self.threeImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.threeSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.twoSubLabel);
        make.top.mas_equalTo(self.threeImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.fourImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.width.height.mas_equalTo(self.threeImageView);
        make.top.mas_equalTo(self.threeSubLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.fourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.fourImageView);
        make.leading.mas_equalTo(self.fourImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.fourSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.threeSubLabel);
        make.top.mas_equalTo(self.fourImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.fiveImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.width.height.mas_equalTo(self.fourImageView);
        make.top.mas_equalTo(self.fourSubLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.fiveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.fiveImageView);
        make.leading.mas_equalTo(self.fiveImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.fiveSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.fourSubLabel);
        make.top.mas_equalTo(self.fiveImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.sixImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.width.height.mas_equalTo(self.fiveImageView);
        make.top.mas_equalTo(self.fiveSubLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.sixLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.sixImageView);
        make.leading.mas_equalTo(self.sixImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.sixSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.fiveSubLabel);
        make.top.mas_equalTo(self.sixImageView.mas_bottom).offset(10 * SCREENH6);
    }];
}


- (UIImageView *)setupImageViewWithImage:(NSString *)image{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.image = ImageNamed(image);
    
    return imageView;
}


- (UILabel *)setupLabelWithString:(NSString *)string WithType:(NSString *)type{
    
    UILabel * label = [UILabel new];
    
    label.textColor = BLACK_COLOR;
    label.text = string;
    label.numberOfLines = 0;
    if ([type isEqualToString:@"title"]) {
        
        label.font = [UIFont boldSystemFontOfSize:16 * SCREENH6];
    }else{
        
        label.font = [UIFont systemFontOfSize:15 * SCREENH6];
    }
    
    return label;
}

- (void)backToView {
    
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
